package com.sg.hms.DaoImpl;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;

import com.sg.hms.Dao.EmployeeDao;
import com.sg.hms.Model.Employee;
import com.sg.hms.Model.User;
import com.sg.hms.Util.JDBCUtil;

public class EmployeeDaoImpl implements EmployeeDao{
    
	@Override
	public Employee selectEmployeeByElId(int elId) {
		// TODO Auto-generated method stub
		Employee em=null;
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("select * from employee where elId=?");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setInt(1,elId);
			ResultSet rs=pst.executeQuery();
			if(rs.next()){
				em=new Employee();
				em.setElId(rs.getInt("elId"));
				em.setElName(rs.getString("elName"));
				em.setdId(rs.getInt("dId"));
				em.setElSex(rs.getString("elSex"));
				em.setElAge(rs.getInt("elAge"));
				//日期转换
				Date date=rs.getDate("enterTime");
				java.util.Date d=new java.util.Date(date.getTime());
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String strdate=sdf.format(d);
				em.setEnterTime(strdate);
				
				em.setTellphone(rs.getString("tellphone"));
				em.setSalary(rs.getDouble("salary"));
				em.setState(rs.getString("state"));
			}
			pst.close();
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return em;
	}

}
